<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>疫苗固有信息管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		/* 批号类型1疫苗2注射器 */
		var batchType = '${batchType}';
		$(document).ready(function() {
			//$("#name").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
			
			$(document).on('change','#vaccineName',function(){
				var str=$("#vaccineName").val();
				var com=$("#companyName").val();
				if(str=='请选择'){
					$("#companyName").find("option").remove(); 
					$("#companyName").select2();
					initCompanyName(com);
					return ;
				}
				var url = "${ctx}/vaccinate/bsVaccineBatchno/getCompanyVaccId";
				var select='<option value="请选择">--请选择--</option>';
				$("#companyName").find("option").remove(); 
				$("#companyName").select2();
				$.ajax({
					url:url,
					data:{"id":$("#vaccineName").val()},
					success:function(data){
							data=$.parseJSON(data); 
							for(var i=0;i<data.length;i++){
								select += "<option>" + data[i].companyName + "</option>";
							}
							$("#companyName").append(select);
						}
				});
			});
		});
		
		/* $(document).on('change','#vaccineName',function(){
				var str=$("#vaccineName").val();
				var com=$("#companyName").val();
				if(str=='请选择'){
					$("#companyName").find("option").remove(); 
					$("#companyName").select2();
					initCompanyName(com);
					return ;
				}
				var url = "${ctx}/vaccinate/bsVaccineBatchno/getCompanyName?id="+id;
				var select='<option value="请选择">--请选择--</option>';
				$("#companyName").find("option").remove(); 
				$("#companyName").select2();
				$.ajax({
					url:url,
					type: "GET",
					dataType:"json",
					cache: false,
					async:false,
					data:{"id":$("#vaccineName").val()},
					success:function(data){
							data=$.parseJSON(data);
							for(var i=0;i<data.length;i++){
								select += "<option>" + data[i].companyName + "</option>";
							}
							$("#companyName").append(select);
						}
				});
			})
		});  */
		
		function closeIframe(){
			var index = parent.layer.getFrameIndex(window.name);
			if(index){
				parent.layer.close(index);
			}else{
				window.location.href = "${ctx}/vaccinate/bsVaccineBatchno/manageBatchno?batchType=2";
			}
		}
		
		function make(){
			 $("div[data-line=line1]").find("span[data=add]").text("已查询");
		}
		
		function rese(){			
			var selects = $("select");			
			for(var i=0;i<selects.length;i++){
				selects[i].options[0].selected = true; 

			}
			location.reload();
		}
		
		function checkBatchno(){
			var url = "${ctx}/vaccinate/bsVaccineBatchno/checkBatchno";
			$.ajax({
				url :url,
				data :{"batchno":$("#batchno").val()} ,
				success : function(data){
					if(data.length>0){
						$("#ll").text("该批次已存在!");
					}else{
						$("#ll").text("");
					}
				}
			});
		}
		function save(){
			if($("#batchno").valid()&& $("#outBoundDate").valid()){
				$.ajax({
					url : "${ctx}/vaccinate/bsVaccineBatchno/saveBatchno",
					data :{"vid": $("#id").val(), 
						   "batchno" : $("#batchno").val(),
						   "outBoundDate" : $("#outBoundDate").val(),
						   "vaccineId" : $("#vaccineName").val(),
						   "spec" : $("#spec").val(),
						   "companyName" : $(".input-text").val(),
						   "batchType" : batchType
					},
					success: function(data){
						if(data){
							layer.msg("保存成功!");
							setTimeout('closeIframe()',2000);
						}
					}
				});
			}
		}
		
		function change(){
			$(".input-text").val($('#companyName').val());
		}
	</script>
	
	<style type="text/css">
		body{
			padding:20px;
		}
		.minWidth {
			min-width: 500px;
		}
		
		@media ( min-width : 789px) and (max-width: 1098px) {
			.secondChild {
				margin-left: 0
			}
		}
		[class*="span"] {
			margin-left: 0px;
		}
		.box{
			position: relative;
			height: 26px;
		}
		.input-text{
			width: 296px;
			height: 26px;
			/* border: none; */
			outline-color: #ccc;
			/* box-sizing: border-box; */
			padding: 0px;
			position: absolute;
			/* left: 2px;
			top: 2px; */
			z-index: 1;
		}
		.selected{
			width: 330px;
			height: 28px;
		    border: 1px solid #e6e0e0;
			outline-color: #ccc;
			padding: 0px;
			border-radius: 6px;
			position: absolute;
			/* left: 0;
			top: 0; */
			z-index: 0;
			/* background: #e6e0e0; */
		}
	</style>
</head>
<body>
	<ul class="nav nav-tabs">
		
	</ul><br/>
	<form:form id="inputForm" modelAttribute="bsVaccineBatchno" action="${ctx}/vaccinate/bsVaccineInfo/save" method="post" class="form-horizontal">
		<input type="hidden" id="id"/>
		<input type="hidden" id="batchType"/>
		<sys:message content="${message}"/>

	<div class="row-fluid">
		<div class="control-group span6 minWidth" data-line="line1">
			<label class="control-label">注射器类型：</label>
			<div class="controls">
				<select id="vaccineName" name="vaccineName" class="span7" >
					<option value="">--请选择--</option>
					<c:forEach items="${fns:getDictList('batch_syringe_type')}" var="dict">
						<option value="${dict.value}">${dict.label}</option>
					</c:forEach>
				</select>
			    <span class="help-inline" data="add"></span>
			</div>
		</div>
		
		<div class="control-group span6 minWidth" data-line="line2">
			<label class="control-label">生产企业：</label>
			<div class="controls" id="app" class="box">
				<input class="input-text" type="text" />
				<!-- <div class="bg"></div> -->
				     <select id="companyName" name="companyName" class="selected" onchange="change()">
				     </select>
				     <p></p>
				<span class="help-inline" data="add"></span>
			</div>
		</div>
	</div>	

	<div class="row-fluid">
		<div class="control-group span6 minWidth">
			<label class="control-label">规格：</label>
			<div class="controls">
				<select name="spec" id="spec" class="span7">
					<option value="">--请选择--</option>
					<c:forEach items="${fns:getDictList('syringe_spec')}" var="dict">
						<option value="${dict.value}">${dict.label}</option>
					</c:forEach>
				</select>
<!-- 				<input type="text" id="spec" name="spec" readonly="true"  maxlength="32" class="span7"/> -->
			</div>
		</div>
	
		<div class="control-group span6 minWidth">
			<label class="control-label">批号：</label>
			<div class="controls">
				<input type="text" id="batchno" name="batchno"   maxlength="32" class="span7  required" onblur="checkBatchno()"/>
				<label id="ll" style="color:red"></label>
			</div>
		</div>
	<div class="row-fluid">
		<div class="control-group span6 minWidth">
			<label class="control-label">有效日期至：</label>
			<div class="controls">
					<input id="outBoundDate" name="outBoundDate" type="text" readonly="readonly" maxlength="20" class="span7 Wdate required"
					value="" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:true});"/>
			</div>
		</div>
	</div>	
	
		<div class="form-actions">
			<%-- <shiro:hasPermission name="vaccineinfo:bsVaccineInfo:edit"> --%>
			<%-- </shiro:hasPermission> --%>
			<input id="btnSubmit" class="btn btn-primary" type="button"  onclick="save()" value="保 存"/>&nbsp;&nbsp;
			<input id="btnReset" class="btn btn-primary" type="button" onclick="rese()" value="重置"/>&nbsp;&nbsp;
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>&nbsp;&nbsp;
			<input id="btnClose" class="btn btn-primary" type="button" onclick="closeIframe()" value="关闭"/>
		</div>
</div>
	</form:form>
</body>
</html>